<?php

/**
 * 模拟post进行url请求
 * @param string $url
 * @param array $post_data
 * @param string $dataType
 * @return bool|mixed
 */

function request_post($post_data = array(), $dataType = '', $url)
{
    if (empty($url) || empty($post_data)) {
        return false;
    }
    // save_log('POST', json_encode($post_data, JSON_UNESCAPED_UNICODE));
    $curlPost = $post_data;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    if ($dataType == 'json') {
        curl_setopt(
            $ch,
            CURLOPT_HTTPHEADER,
            array(
                'Content-Type: application/x-www-form-urlencoded;charset=UTF-8',
                'Content-Length: ' . strlen($curlPost),
            )
        );
    }
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $data = curl_exec($ch);
    // save_log('RESPONSE', $data);
    return $data;
}